package com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller;

import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.PageInfo;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.Result;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoAddReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoCompleteReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoListDoneTaskReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoListLaunchTaskReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoListReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoListTodoTaskReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.req.DemoLeaveInfoUpdateReqVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.resp.DemoLeaveInfoDetailRespVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.entity.resp.DemoLeaveInfoListRespVO;
import com.ideaaedi.zoo.example.springboot.bpmn.flowable.controller.demo4.service.DemoLeaveInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请假申请
 *
 * @author Administrator
 * @since 1.0.0
 */
@Validated
@RestController
@Tag(name = "请假申请")
@RequestMapping("/demo-leave-info")
public class Demo4工作流与业务表集合使用Controller {

    @Resource
    private DemoLeaveInfoService demoLeaveInfoService;


    @PostMapping("/add")
    @Operation(summary = "新增申请（新增为草稿 或 直接发起申请）")
    public Result<DemoLeaveInfoDetailRespVO> add(@RequestBody @Validated DemoLeaveInfoAddReqVO req) {
        return Result.success(demoLeaveInfoService.add(req, true));
    }


    @PostMapping("/release/{id}")
    @Operation(summary = "发起申请")
    public Result<DemoLeaveInfoDetailRespVO> release(@Parameter(description = "要发布流程的数据id")
                                                     @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return Result.success(demoLeaveInfoService.release(id));
    }


    @Operation(summary = "删除（删除业务数据 & 删除申请数据）")
    @DeleteMapping("/delete/{id}")
    public Result<DemoLeaveInfoDetailRespVO> delete(@Parameter(description = "要删除数据的id")
                                                  @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return Result.success(demoLeaveInfoService.delete(id));
    }


    @Operation(summary = "撤销（终止申请）")
    @DeleteMapping("/terminate/{id}")
    public Result<DemoLeaveInfoDetailRespVO> terminate(@Parameter(description = "要撤销数据的id")
                                                  @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return Result.success(demoLeaveInfoService.terminate(id));
    }


    @PutMapping("/update")
    @Operation(summary = "修改")
    public Result<DemoLeaveInfoDetailRespVO> update(@RequestBody @Validated DemoLeaveInfoUpdateReqVO req) {
        return Result.success(demoLeaveInfoService.update(req));
    }


    @PutMapping("/complete-task")
    @Operation(summary = "审批")
    public Result<DemoLeaveInfoDetailRespVO> completeTask(@RequestBody @Validated DemoLeaveInfoCompleteReqVO req) {
        return Result.success(demoLeaveInfoService.complete(req));
    }
    
    @PostMapping("/list-todo-apply")
    @Operation(summary = "待处理申请（不含流程数据）")
    public Result<PageInfo<DemoLeaveInfoListRespVO>> listTodoApply(@RequestBody @Validated DemoLeaveInfoListTodoTaskReqVO req) {
        return Result.success(demoLeaveInfoService.listTodoApply(req));
    }
    
    @PostMapping("/list-done-apply")
    @Operation(summary = "已处理申请（不含流程数据）")
    public Result<PageInfo<DemoLeaveInfoListRespVO>> listDoneApply(@RequestBody @Validated DemoLeaveInfoListDoneTaskReqVO req) {
        return Result.success(demoLeaveInfoService.listDoneApply(req));
    }
    
    @PostMapping("/list-launch-apply")
    @Operation(summary = "已发起申请（不含流程数据）")
    public Result<PageInfo<DemoLeaveInfoListRespVO>> listLaunchApply(@RequestBody @Validated DemoLeaveInfoListLaunchTaskReqVO req) {
        return Result.success(demoLeaveInfoService.listLaunchApply(req));
    }

    @PostMapping("/list")
    @Operation(summary = "查申请列表（仅查业务数据，不查流程数据）")
    public Result<PageInfo<DemoLeaveInfoListRespVO>> list(@RequestBody @Validated DemoLeaveInfoListReqVO req) {
        return Result.success(demoLeaveInfoService.list(req));
    }
    
    @Operation(summary = "查申请详情（含流程数据）")
    @GetMapping("/detail/{id}")
    public DemoLeaveInfoDetailRespVO applyDetail(@Parameter(description = "要查询数据的id")
                                                  @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return demoLeaveInfoService.applyDetail(id);
    }
    
    @Operation(summary = "查审批任务详情")
    @GetMapping("/task-detail/{taskId}")
    public Object taskDetail(@Parameter(description = "要查询审批任务id")
                             @PathVariable("taskId") @NotNull(message = "taskId cannot be null.") String taskId) {
        return demoLeaveInfoService.taskDetail(taskId);
    }

}